package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author wa1nut
 */
@Mapper
public interface BrandMapper {

    /**
     * 查询所有
     * @return 分页对象
     */
    @Select("select id, name, image, letter, seq from tb_brand")
    Page<Brand> findAll();

    /**
     * 添加
     * @param brand 品牌
     */
    @Insert("insert into tb_brand(name, image, letter, seq)\n" +
             "values(#{name}, #{image}, #{letter}, #{seq}) ")
    void insert(Brand brand);

    /**
     * 删除
     * @param id 序号
     */
    @Delete("delete from tb_brand where id =#{id}")
    void delete(Integer id);

    /**
     * 根据ID查询
     * @param id 序号
     * @return 品牌对象
     */
    @Select("select id, name, image, letter, seq from tb_brand where id = #{id}")
    Brand findById(Integer id);


    /**
     * * 根据条件查询
     * @param brand 品牌
     * @return 分页对象
     */

    List<Brand> selectByCondition(Brand brand);

    /**
     * 更新数据库
     * @param brand 品牌
     */
    void update(Brand brand);
}
